package com.zby.simulationHibernate.util.reflect;

import com.zby.simulationHibernate.util.common.CommonUtil;
import com.zby.simulationHibernate.util.common.StringUtil;

/**
 * Created By zby on 16:47 2019/1/29
 * <p>
 * 处理与类有关的信息
 */

public class ClassUtil<T> {

    /**
     * Created By zby on 16:50 2019/1/29
     * 处理与类相关的信息
     */
    public static <T> String getClassNameByGenericity(T t) {
        if (CommonUtil.isNull(t)) {
            throw new IllegalArgumentException("参数错误t=" + t);
        }
        Class<?> clazz = t.getClass();
        String className = clazz.getName();
        className = className.substring(className.lastIndexOf(".") + 1, className.length());
        return StringUtil.firstLetterToLower(className);
    }

    /**
     * Created By zby on 16:50 2019/1/29
     * 处理与类相关的信息
     */
    public static <T> String getClassNameByClass(Class<T> clazz) {
        if (CommonUtil.isNull(clazz)) {
            throw new IllegalArgumentException("参数错误t=" + clazz);
        }
        String className = clazz.getName();
        className = className.substring(className.lastIndexOf(".") + 1, className.length());
        return StringUtil.firstLetterToLower(className);
    }

}
